/*
 * Project: a2
 * Copyright (C) 2008 ralfoide gmail com,
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.alfray.a2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

import com.alfray.a2.gameplay.GameActivity;

public class A2Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.launcher);

        View game1 = (View) findViewById(R.id.game1);
        View game2 = (View) findViewById(R.id.game2);

        game1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                onClassicGame();
            }
        });

        game2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                onQuickGame();
            }
        });
    }

    // --------------------------
    // Options menu

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, R.string.new_game1,  0, R.string.new_game1).setIcon(R.drawable.ic_menu_add);
        menu.add(0, R.string.new_game2,  0, R.string.new_game2).setIcon(R.drawable.ic_menu_add);
        menu.add(0, R.string.cont_game,  0, R.string.cont_game).setIcon(R.drawable.ic_menu_set_as);
        menu.add(0, R.string.help,  0, R.string.help).setIcon(R.drawable.ic_menu_help);
        menu.add(0, R.string.settings,  0, R.string.settings).setIcon(R.drawable.ic_menu_preferences);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
        case R.string.new_game2:
            onQuickGame();
            break;
        case R.string.new_game1:
            onClassicGame();
            break;
        case R.string.cont_game:
            onContinueGame();
            break;
        case R.string.settings:
            onPrefs();
            break;
        case R.string.help:
            onHelp();
            break;
        }
        return super.onOptionsItemSelected(item);
    }

    // --------------------------

    private void onQuickGame() {
        Toast.makeText(this, "Starting Quick game", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(this, GameActivity.class);
        startActivity(intent);
    }

    private void onClassicGame() {
        Toast.makeText(this, "Starting Classic game", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(this, GameActivity.class);
        startActivity(intent);
    }

    private void onContinueGame() {
        Toast.makeText(this, "TODO: Continue game", Toast.LENGTH_SHORT).show();
    }

    private void onHelp() {
        Intent intent = new Intent(this, AboutActivity.class);
        startActivity(intent);
    }

    private void onPrefs() {
        Intent intent = new Intent(this, PrefsActivity.class);
        startActivity(intent);
    }

}